Skip to content

fix(core): startup removes dead writers' temporary files - #752

Merged
V3RON merged 12 commits into
mainfrom
bug/699
Oct 20, 2026
Merged

V3RON merged 12 commits into
mainfrom
bug/699

Conversation

@V3RON

@V3RON V3RON commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #699

Status

Built: the daemon's startup removes dead-pid .<name>.<pid>.<uuid>.tmp files and .<root>.<pid>.<id>.staging directories beside state.json, in the data directory and beside each device root. Live-pid ones stay.

Done when

  • Startup removes dead-pid .tmp files and keeps live-pid ones
  • Leftover .staging directories from a dead process are removed or reported

Assumptions

  • Assumption: .staging directories are cleaned like .tmp files; ensureOwnedRoot puts the writer's pid in the staging name (from the issue Decisions).
  • Assumption: where the sweep runs — at the start of the worker's startup converge, once, not in doctor --fix.
  • Assumption: a staging name from a caller that passes no pid has no pid segment and is never swept — the daemon always passes its pid.

Review

Spec review: 1 blocking, 1 fixed, 0 notes. Code review: 5 blocking, 5 fixed, 0 notes. Claims review: 0 blocking, 0 fixed, 0 notes.
Rounds: 2. Tokens: 2.1M.
Runs: 16. Cost USD: 3.9541. Agent seconds: 2843.

Written by an agent.

@V3RON

V3RON commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

Decision taken

Question: should #699 also clean .staging directories? Staging names carry no pid, so a dead writer's leftover can't be told from a live one.

  • Skip staging, follow-up task: smaller change; the issue's .staging expectation stays unmet.
  • Put the writer pid in the staging name and sweep like .tmp files: the issue is fully met; staging names change shape.

Taken: the second, the issue names .staging explicitly. Revert: drop the pid from the staging name in ensureOwnedRoot and remove its sweep branch and test.

Written by an agent.

@V3RON

V3RON commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

Decision taken

Question: what to do with legacy .staging directories without a pid (written before this change)?

  • Leave silently: no deletion risk; they pile up unseen.
  • Log them, never delete: matches the triage report's "report legacy staging directories"; no deletion risk.
  • Delete by age: cleans them, but may remove a live writer's directory.

Taken: log, never delete. Revert: remove the log line and its test.

Written by an agent.

@V3RON

V3RON commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

Review ledger

Runs: 16. Cost USD: 3.9541. Agent seconds: 2843.
Tokens input 394, output 92684, cache read 6384551, cache write 608205.

  • build implementer: claude-sonnet-5-5 187 s $0.2382
  • build implementer: claude-sonnet-5-5 124 s $0.2361
  • audit implementer: claude-sonnet-5-5 126 s $0.1718
  • fix implementer: claude-sonnet-5-5 114 s $0.1234
  • review 1 reviewer both: claude-sonnet-5-5 304 s $0.1354
  • review 1 code both: claude-opus-5-5 241 s $1.0152
  • review 1 spec: claude-sonnet-5-5 33 s $0.1157
  • review 1 claims: claude-sonnet-5-5 59 s $0.1099
  • fix 1 implementer: claude-sonnet-5-5 928 s $0.4443
  • review 2 reviewer both: claude-sonnet-5-5 264 s $0.1604
  • review 2 code both: claude-opus-5-5 195 s $0.7199
  • review 2 spec: claude-sonnet-5-5 36 s $0.1142
  • review 2 claims: claude-sonnet-5-5 39 s $0.1217
  • fix 2 implementer: claude-sonnet-5-5 84 s $0.1052
  • review fix-check reviewer both: claude-sonnet-5-5 68 s $0.0864
  • fix fix-check implementer: claude-sonnet-5-5 41 s $0.0563
    Finding outcomes: {"fixed":6}. Classes: {"architecture 9":1,"safety 1, deletes files Simlock never wrote":1,"safety 1, safety 8":1,"simplest-fix line not delivered":1,"testing 2":1,"testing 3":1}.
{
 "findings": [
  {
   "id": "R1",
   "role": "code",
   "class": "safety 1, safety 8",
   "outcome": "fixed",
   "path": "src/core/write-leftovers.ts",
   "fix": "4ed79366"
  },
  {
   "id": "R2",
   "role": "code",
   "class": "testing 2",
   "outcome": "fixed",
   "path": "src/daemon/main.test.ts",
   "fix": "4ed79366"
  },
  {
   "id": "R3",
   "role": "code",
   "class": "testing 3",
   "outcome": "fixed",
   "path": "src/daemon/main.ts",
   "fix": "4ed79366"
  },
  {
   "id": "R4",
   "role": "code",
   "class": "architecture 9",
   "outcome": "fixed",
   "path": "src/core/write-leftovers.ts",
   "fix": "492c366f"
  },
  {
   "id": "R5",
   "role": "spec",
   "class": "simplest-fix line not delivered",
   "outcome": "fixed",
   "path": "src/core/write-leftovers.ts",
   "fix": "4ed79366"
  },
  {
   "id": "R6",
   "role": "code",
   "class": "safety 1, deletes files Simlock never wrote",
   "outcome": "fixed",
   "path": "src/core/write-leftovers.ts",
   "fix": "6827aa58"
  }
 ]
}

Written by an agent.

@V3RON
V3RON marked this pull request as ready for review October 20, 2026 11:35
@V3RON
V3RON merged commit 8db8112 into main Oct 20, 2026
26 checks passed
@V3RON
V3RON deleted the bug/699 branch October 20, 2026 11:50
V3RON added a commit that referenced this pull request Oct 21, 2026
…ew (#794)

## What this is

A review replay harness, and the process review it was built for.

`docs/internal/PROCESS-REVIEW-2026-10-21.md` reads the deliver and spec
runs after #739: where the time went, the obstacles (stale stacked
bases, stack tooling, CI flakes, late ADR reviews, the round cap),
review quality, spec-session holes, test growth and which instruction
files agents actually open. It lists 22 changes, each with the number
that judges it, and says the replay harness comes first.

The harness:

- `review-inputs.sh` takes `REVIEW_HEAD`, `REVIEW_BASE` and
`REVIEW_RULES`, so a merged PR's snapshot can be reviewed again, with
today's or another commit's rules.
- `replay-freeze.mjs` pins a round's head, base and previous as
`refs/replay/<PR>/<round>/*` on origin and the PR's Review ledger as the
blob `refs/replay/<PR>/truth`, never in the checkout.
- `review-replay.sh` builds the blind inputs for a snapshot and prints
the reviewer's prompt, tagged `stage=replay`; `--lens` replays one lens
alone.
- `review-score.mjs` scores a replay's findings (JSON or a lens report)
against the truth and appends a row to `.agents/replay/results.jsonl`.
- `review-metrics.mjs` leaves `stage=replay` runs out unless `--replay`;
the reviewer has a replay clause.

## Replayed so far

- #752 round 1: two valid runs of four, both 4/6 of the ledger, both
missing the safety finding (one saw it and downgraded it to a note),
both raising one finding the real review did not.
- #775 round 1: 6/10 by hand at the original's cost; found the
retry-column sibling and the socket probe in round 1, which the real
review found in round 2 and at the fix-check.
- #775 round 2: 3/3, same cost.

Harness defects found by the examples and fixed in this PR: the
coordinator reading the truth file, coordinators self-checking instead
of spawning lenses, lens runs tagged as real reviews.

*Written by an agent.*
V3RON added a commit that referenced this pull request Oct 21, 2026
…andidates are probed, mechanical fix-checks spawn no lens, the audit proves coverage (#799)

## What this is

Layer four of `docs/internal/PROCESS-REVIEW-2026-10-21.md`: the review
changes, items 13, 14, 15 and 23. Stacked on #798.

- Item 13: round 1 reports every site of a confirmed defect class. The
real #775 round 1 found one STRICT INTEGER column and round 2 its
sibling; a replay found both in round 1, so the reach is there and the
brief now asks for it. A sibling found in round 2 is recorded as round
1's miss.
- Item 23: a candidate in a safety class is never downgraded to a note
or dismissed at synthesis on reasoning alone; the coordinator probes it
or it blocks. Both #752 replays lost the safety finding that way; one
coordinator saw it and wrote "name-only matching is narrow".
- Item 15: a fix-check whose every hunk is mechanical spawns no lens;
the coordinator reads the diff and records it. One semantic hunk sends
only the lens it reaches.
- Item 14: the audit lists every changed function and proves a test goes
red when its body is deleted (`covered <c>/<f>` on the audit line).
About 20 of 45 review findings were test-coverage classes the audit
should have caught.

## Verification

Replayed with these rules through `review-replay.sh <pr> 1 a580434`,
once each, against the baseline runs of the same snapshots (write-up,
sections 4.5 to 4.8):

| Snapshot | Baseline recall | With the changes | USD | Minutes |
| --- | --- | --- | --- | --- |
| #752 round 1 | 4/6 | 6/6 | 1.41 → 1.67 | 12 → 17 |
| #775 round 1 | 6/10 | 8/10 | 6.47 → 8.07 | 34 → 37 |

#752: the safety finding came back blocking with a reproduction, where
both baseline runs had downgraded it to a note; EPERM-counted-dead
stayed blocking for want of a probe (item 23). #775: all three STRICT
INTEGER columns in one round-1 finding, with probes, where the real
review needed round 2 (item 13); the socket probe found in round 1
again. Still missed on #775: the fake table accepting extra keys. Cost
per round 1 is up about 20 percent; the rounds it should remove are
measured on the next deliveries. Rows are in
`.agents/replay/results.jsonl`.

*Written by an agent.*
V3RON added a commit that referenced this pull request Nov 27, 2026
…nd a finding's class is one rule (#1918)

## Why

A change to the review is judged on two replay snapshots from October,
with ledger findings only. Nineteen bugs escaped review in the last four
weeks and none is in that proof set. The weekly recurring-findings count
also splits one rule over many class strings.

## What

- Round 1 of #1210, #1235, #1626, #1360, #1446 and #1620 is frozen under
`refs/replay/`.
- `replay-freeze.mjs --escaped` pins the bugs a review let through:
issue, fix commit, file and lines at the reviewed head. Twelve are
recorded (table in the first comment); the list lives on origin, never
in the checkout. A freeze that would change a pinned truth is refused
without `--replace-truth`, which keeps the stored entries.
- `review-score.mjs` reports recall on escaped bugs as its own number.
- `review-metrics.mjs --findings` writes `testing 3: error path` back as
class `testing 3` plus `detail`, and refuses a class that names a rule
file and no rule number. `review-ledger.mjs` posts the file as written
back.

## Proof

```
1 Snapshots. Fresh clone of this branch, review-replay.sh <pr> 1 for the six PRs (no agent runs):
  6 of 6 exit 0; 12 head and base refs and 6 truth blobs fetched;
  merge-base equals the real review's for the 5 PRs with a transcript.
2 Score. Stored #752 row rulesC-a5804341 rebuilt as a findings file:
  old and new script print the same lines and row: recall 3/6, 7 unmatched (the stored numbers).
  Hand-made result on #1235 (4 escaped bugs): 2/4. Not counted: a finding on the
  bug's file with no line, on other lines, or recorded as a note.
3 Classes. review-metrics.mjs --findings over the 316 ledgers (854 findings, 645 fixed):
  distinct classes of fixed findings 444 -> 370; 101 findings got a detail;
  7 ledgers refused ("testing: ...", "safety: ...", bare "documentation").
  recurring-findings.mjs --days 30 on the same ledgers, before -> after:
  testing 3 44 -> 60 PRs, testing 10 31 -> 43, documentation 7 30 -> 36, testing 2 20 -> 27.
Escaped bugs: q6.json blames 13 on these PRs; each fix was read.
  Dropped #1629 (#1360): ADR 0009 §4 decided it and a test pinned it since 6 October.
  Moved #1780 from #1620 to #1235. #1802 is recorded for #1235 and #1620.
  #1750 and #1560: the defect is older than the PR, which added one more instance.
Pinned truth. On origin: a second freeze of #1360 left its truth blob as it was;
  a freeze of #1620 with a changed list was refused, nothing written or pushed.
Not verified: no replay was run, so today's recall on the 12 bugs is unknown.
  #1446 has no transcript here: its base is the merge-base, its baseline cost unknown.
  --replace-truth ran only in the unit test, against a local origin.
```

## Review

Spec review: skipped. Code review: 3 blocking, 3 fixed, 1 notes. Claims
review: 1 blocking, 1 fixed, 0 notes.
Rounds: 2. Tokens: 2.2M.
Assessment: complete

*Written by an agent.*
V3RON added a commit that referenced this pull request Nov 27, 2026
… role uses (#1921)

## Why

Sub-agents start with text they never use. `spec-checker` and
`bug-triager` had no `tools:` line, so each run began with every tool,
the skill list and the deferred-tool list: about 50k tokens. The memory
index, root `AGENTS.md` and the user's rules reach every sub-agent:
about 10.6k tokens. The review coordinator, the hardware verifier and
the `deliver` orchestrator get module manuals, though they write and
judge no code.

## What

- `spec-checker` and `bug-triager` list the tools their past runs used.
- The three lenses, `reviewer`, `hardware-verifier` and `spec-explorer`
set `omitClaudeMd: true`.
- `manual-hook.mjs` sends no manual to `reviewer`, to
`hardware-verifier`, or to a main session once its transcript shows
`deliver` started.

## Proof

Tokens of the first request, same prompt, a fresh session before and
after:

```
role               before   after
spec-checker       50,536  16,856
bug-triager        51,205  19,474
spec-explorer      16,025   5,450
spec-reviewer      15,404   4,829
code-reviewer      15,771   5,196
claims-reviewer    15,203   4,628
reviewer           24,124  13,549
hardware-verifier  16,037   5,462
```

```
tools    324 spec-checker and 142 bug-triager transcripts recounted
flag     instructions attachment gone in all six roles (MEMORY.md, AGENTS.md, context7.md)
replay   frozen #752 round 1 with the flag: recall 4/6, 0 hits on non-defects (stored runs: 0/6 to 4/6)
hook     644 manuals to 149 main sessions replayed: 169 withheld in 70 deliver sessions, 0 elsewhere
         with reviewer and verifier: 4.61M of 35.74M chars in 21 days
tests    3 new cases; 5 mutants of the new exits, each fails a named assertion
```

Not verified: a full `check-spec` or triage run with the new `tools:`
lines, and a slow-lane run by the verifier. Details are in the first
comment.

## Review

Spec review: skipped. Code review: 0 blocking, 1 fixed, 0 notes. Claims
review: 1 blocking, 1 fixed, 0 notes.
Rounds: 2. Tokens: 2.3M.
Assessment: complete

*Written by an agent.*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Leftover .tmp files and .staging directories from a crashed write are never cleaned up

1 participant